<template>
  <div class="app-container">
    <!-- 农资信息表-管理按钮 -->
    <div class="search-bar">
      <el-input v-model="searchData.nzbh" placeholder="请输入农资编号查询" />
      <el-input v-model="searchData.nzmc" placeholder="请输入农资名称查询" />

      <el-button
        v-waves
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="searchBtnHandle"
        >查询</el-button
      >
      <el-button
        v-waves
        type="info"
        size="small"
        icon="el-icon-refresh"
        @click="resetTableList"
        >显示全部</el-button
      >
      <div style="float: right">
        <el-button
          v-waves
          type="primary"
          icon="el-icon-plus"
          @click="openAdd"
          size="small"
          v-permission="'jtnc-nzxx-krNzxx-add'"
          >添加农资信息
        </el-button>
      </div>
    </div>
    <!-- 农资信息表-列表 -->
    <el-table
      ref="dataTable"
      :data="tableData"
      stripe
      border
      @selection-change="handleTableSelectChange"
      v-loading="isLoading"
    >
      <el-table-column
        type="selection"
        width="50"
        align="center"
        header-align="center"
      />
      <el-table-column label="农资编号" prop="nzbh" align="center" />
      <el-table-column label="农资名称" prop="nzmc" align="center" />
      <el-table-column label="规格" prop="gg" align="center" />
      <el-table-column label="单位" prop="unit" align="center" />
      <el-table-column label="生产厂家" prop="sccj" align="center" />
      <el-table-column label="单价" prop="dj" align="center" />
      <el-table-column fixed="right" label="操作" width="120" align="center">
        <template v-slot="scope">
          <el-button
            type="text"
            style="color: #13ce66"
            size="small"
            @click="openView(scope.row)"
            >详情</el-button
          >
          <el-button
            v-permission="'jtnc-nzxx-krNzxx-update'"
            type="text"
            size="small"
            @click="openUpdate(scope.row)"
            >修改
          </el-button>
          <!-- <el-button
            v-permission="'jtnc-nzxx-krNzxx-delete'"
            style="color: #ff6d6d"
            type="text"
            size="small"
            @click="deleteByIds(scope.row)"
            >删除
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 农资信息表-分页 -->
    <el-pagination
      style="text-align: center; margin-top: 10px"
      layout="total,prev,pager,next,sizes,jumper"
      :page-size="pager.limit"
      :current-page="pager.page"
      :total="pager.totalCount"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <!-- 添加修改弹窗 -->
    <el-dialog
      :title="titleMap[dialogType]"
      :close-on-click-modal="dialogType !== 'view' ? false : true"
      :visible.sync="dialogFormVisible"
      @close="resetTemp"
      width="800px"
      :key="'myDialog' + dialogIndex"
    >
      <el-form
        ref="dataForm"
        :model="temp"
        label-position="right"
        label-width="100px"
        :disabled="dialogType === 'view'"
      >
        <el-form-item
          label="农资编号"
          prop="nzbh"
          :rules="[]"
          v-if="dialogType != 'add'"
        >
          <el-input
            v-model="temp.nzbh"
            placeholder="请输入农资编号"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item
          label="农资名称"
          prop="nzmc"
          :rules="[
            { required: true, message: '请输入农资名称', trigger: 'blur' },
          ]"
        >
          <el-input v-model="temp.nzmc" placeholder="请输入农资名称" />
        </el-form-item>
        <el-form-item
          label="规格"
          prop="gg"
          :rules="[{ required: true, message: '请输入规格', trigger: 'blur' }]"
        >
          <el-input v-model="temp.gg" placeholder="请输入规格" />
        </el-form-item>
        <el-form-item
          label="单位"
          prop="unit"
          :rules="[{ required: true, message: '请输入单位', trigger: 'blur' }]"
        >
          <el-input v-model="temp.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item
          label="生产厂家"
          prop="sccj"
          :rules="[
            { required: true, message: '请输入生产厂家', trigger: 'blur' },
          ]"
        >
          <el-input v-model="temp.sccj" placeholder="请输入生产厂家" />
        </el-form-item>
        <el-form-item
          label="单价"
          prop="dj"
          :rules="[{ required: true, message: '请输入单价', trigger: 'blur' }]"
        >
          <el-input-number
            v-model.number="temp.dj"
            placeholder="请输入单价 (元)"
            :precision="2"
          ></el-input-number>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-waves
          type="primary"
          v-if="dialogType !== 'view'"
          @click="saveData"
          >保存</el-button
        >
        <el-button v-waves @click="dialogFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import waves from "@/directive/waves";
import crudMixin from "@/mixin/crudMixin";
import request from "@/utils/request";
export default {
  directives: { waves },
  mixins: [crudMixin],
  data() {
    return {
      url: {
        list: "/jtnc/nzxx/krNzxx/list",
        add: "/jtnc/nzxx/krNzxx/add",
        info: "/jtnc/nzxx/krNzxx/getById",
        update: "/jtnc/nzxx/krNzxx/update",
        delete: "/jtnc/nzxx/krNzxx/delete",
      },
      idName: "nzId",
    };
  },
  created() {
    this.loadTableList();
    this.resetTemp();
  },
  methods: {},
};
</script>
<style lang="scss" scoped>
.search-bar {
  margin-bottom: 10px;
  ::v-deep {
    .el-input,
    .el-select {
      width: 180px;
      margin-right: 10px;
      margin-bottom: 5px;
    }
  }
}
</style>
